package com.example.scanner_demo;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.fangya.app_scaner_iot.view.CameraView;
import com.fangya.app_scaner_iot.view.Controller;
import com.fangya.app_scaner_iot.view.ScanListener;
import com.fangya.app_scaner_iot.view.decodeBitmapRuslt;
import com.fangya.app_scaner_iot.view.viewResumeListenner;

import java.util.List;


public class MainActivity extends AppCompatActivity implements viewResumeListenner {

    private CameraView barcode_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        barcode_view=(CameraView)findViewById(R.id.barcode_view);
        Controller.createInstance().init(barcode_view);
        //控制扫描声音
        Controller.getInstance().playBeepSound(true);
        //设置接收扫描结果的回调
        Controller.getInstance().setScanListener(new ScanListener() {
            @Override
            public void onScanResult(List<String> list, Bitmap bitmap) {
                Log.e("扫描的条码",list.toString());
            }
        });
        //是否支持的设备名称
        String modlename=Controller.getInstance().isDeviceSupport();
        //设置是否返回图片
        Controller.getInstance().setCropImage(true);
        //设置扫描间隔时间 ms
        Controller.getInstance().setScanInterval(100);
        //设置指示灯亮灯颜色，调
         //       用后指示灯亮3s
        Controller.getInstance().setIndicateLight(1);
        Controller.getInstance().setIndicateLight(1,0);
        //解析出传入图片的条形码或者二维码的单号
//        Controller.getInstance().decodeBitmap(Bitmap);
        //图片的解析结果
        Controller.getInstance().setdecodeBitmapListener(new decodeBitmapRuslt() {
            @Override
            public void ondecodeResult(List<String> list) {
                Log.e("解析图片结果",list.toString());
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        barcode_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //切换摄像头 第一个 index
                Controller.getInstance().changeCamera(1);
            }
        });

    }

    @Override
    public void onViewResume() {
        //开始扫描
        Controller.getInstance().start();
        //设置指示顶部补光灯亮度。
        Controller.getInstance().setFillLight(100);

    }
}